$(function(){
	//ajax请求后台数据
	getShopCustomerManagePageInfo();
	toPage();
});

        //分页参数设置 这些全局变量关系到分页的功能
        var startAllAppoint = 0;
        var limitAllAppoint = 10;
        var currentPageAllAppoint = 1;
        var totalPageAllAppoint = 0;
        var dataLength = 0;
        //ajax请求后台数据
        function getShopCustomerManagePageInfo(){
            $.ajax({
                type:"post",
                async:false,
                url:"../obj/getDeviceList",
                data:{start:startAllAppoint, limit:limitAllAppoint},
                success:function(data){
                    //data=eval("("+data.deviceList+")");
                    getShopCustomesInfo(data.data.list);
                    startAllAppoint = data.data.pageNum;//当前页数(后台返回)
                    totalPageAllAppoint = data.data.total;//总页数(后台返回)

                }
            });

        }



        function getShopCustomesInfo(data){
            var s = "<tr><th>品牌</th><th>型号</th><th>操作</th></tr>";
            $.each(data,function(v,o){
            	 	s+='<tr>';
            	 	s+='<td>'+o.brand+'</td>';
                    s+='<td>'+o.model+'</td>';
                    s+='<td><button" class="layui-btn layui-btn-xs" deviceId="'+o.id+'" record="1" onclick="gotoParent(this);">演示</button></td>';
                    s+='</tr>';
            });

            if(data.length>0){
                $("#device_customerInfo").html(s);
            }else{
                $("#page1").hide();
                $("#device_customerInfo").html("<br/><span style='width:10%;height:30px;display:block;margin:0 auto;'>暂无数据</span>");
            }


        }



        function toPage(){

            layui.use(['form', 'laypage', 'layedit','layer', 'laydate'], function() {
                var form = layui.form,
                    layer = layui.layer,
                    layedit = layui.layedit,
                    laydate = layui.laydate,
                    laypage = layui.laypage;
                

                var nums = 10;
                //调用分页
                  laypage.render({
                    elem: 'devicePaged'
                    ,count: totalPageAllAppoint //得到总页数，在layui2.X中使用count替代了，并且不是使用"总页数"，而是"总记录条数"
                   // ,curr: currentPageAllAppoint
                    //,skip: true
                    ,layout:['count','prev','page','next','limit','skip']
                    ,jump: function(obj, first){

                        currentPageAllAppoint = obj.curr;
                        startAllAppoint = (obj.curr-1)*limitAllAppoint;
                      //document.getElementById('biuuu_city_list').innerHTML = render(obj, obj.curr);
                      if(!first){ //一定要加此判断，否则初始时会无限刷新
                      getShopCustomerManagePageInfo();//一定要把翻页的ajax请求放到这里，不然会请求两次。
                          //location.href = '?page='+obj.curr;
                        }
                    }
                  });


            });
        };
        
        function gotoParent(this){
        	$(this).attr("deviceId");
        	var record = $(this).attr("record");
        	if(record=="1"){
        		$(this).html("结束");
        	}else{
        		$(this).html("演示");
        	}
        }